using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Modules.Abstracts;
using FiltronASP.Models;
using FiltronASP.Models.DAO;
using FiltronASP.Models.DAO.Interfaces;

namespace FiltronASP.Modules
{
    public class lastSearchesModule : AbstractModule
    {
        public override string GenerateContent(FiltronASP.Models.Page page)
        {
            String toReturn = String.Empty;
            toReturn += String.Format("<h3 class=\"booked\">{0}</h3>", Helpers.Translations.translationHelper.getTranslation("_lastSearches", Convert.ToInt32(page.language_id)));

            ILastSearchesDAO lastSearchesDAO = new LastSearchesDAO();
            IQueryable<LastSearch> lastSearchesCollection = lastSearchesDAO.getLastSearches(Convert.ToInt32(page.language_id));
            if (lastSearchesCollection != null)
            {
                List<LastSearch> lastSearchList = new List<LastSearch>();
                lastSearchList = lastSearchesCollection.ToList();
                for (int i = 0; i < 50; )
                {
                    toReturn += "<ul>";
                    List<LastSearch> lastSearchListInLoop = lastSearchList.Skip(i).Take(10).ToList();
                    foreach (LastSearch singleLoop in lastSearchListInLoop) { 
                        toReturn += String.Format("<li><a href=\"{2}{1}\">{0}</a></li>", 
                        singleLoop.last_search_name, 
                        singleLoop.last_search_link, 
                        Helpers.Translations.translationHelper.getTranslation("_lastSearchesLink", Convert.ToInt32(page.language_id)));
                    }
                    toReturn += "</ul>";
                    i += 10;
                    
                }
            }

            IPageDAO pageDAO = new PageDAO();
            IQueryable<Page> pagesCollection = pageDAO.FindByLanguageAndTemplateNameAndPublished(Convert.ToInt32(page.language_id), "LastSearchesList", true);
            if (pagesCollection != null) {
                foreach (Page singlePage in pagesCollection) {
                    toReturn += "<div class=\"lastSearchesSingleLink\"><a href=\" " + singlePage.page_link + " \"> " + Helpers.Translations.translationHelper.getTranslation("_more" ,Convert.ToInt32(page.language_id)) + " &raquo;</a></div>";
                }
            }
            return toReturn;
        }
    }
}
